<?php
namespace app\admin\controller;
use think\Controller;
use think\Db;

class RoleUser extends Controller
{
    public function showroleuser(){
        $data=Db::name("role_user")->select();
        return ['status'=>1,'message'=>'获取成功','data'=>$data];
    }

    public function getone(){
        $role_user_id=input("id");
        $data=Db::name("role_user")->where('role_user_id',$role_user_id)->find();
        return ['status'=>1,'message'=>'获取成功','data'=>$data];
    }

    public function insert(){
        $data=input();
        if(Db::name("role_user")->insert($data)){
            $role_user_id=Db::name("role_user")->getLastInsID();
            return ['status'=>1,'message'=>'添加成功','role_user_id'=>$role_user_id];
        }
        else
            return ["status"=>0,'message'=>'添加失败'];
    }

    public function update(){
        $data=input();
        if(Db::name("role_user")->where("role_user_id",$data['id'])->setField($data['column'],$data['value']))
            return ['status'=>1,'message'=>'更新成功'];
        else
            return ['status'=>0,'message'=>'更新失败'];
    }

    public function delete(){
        $role_user_id=input("id");
        if(Db::name("role_user")->where("role_user_id",$role_user_id)->delete())
            return ['status'=>1,'message'=>'删除成功'];
        else
            return ['status'=>0,'message'=>'删除失败'];
    }
}